<?php

namespace MoChat\ClientNew\Action;

use Carbon\Carbon;
use Hyperf\DbConnection\Db;
use MoChat\ClientNew\Model\ClientFollowRecord;
use MoChat\ClientNew\Model\ClientNew;
use MoChat\Framework\Action\AbstractAction;
use MoChat\Framework\Constants\ErrorCode;
use MoChat\Framework\Exception\CommonException;
use MoChat\Framework\Request\ValidateSceneTrait;
use MoChat\App\Common\Middleware\DashboardAuthMiddleware;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Qbhy\HyperfAuth\AuthManager;

/**
 * @Controller
 */
class DetailJyfw extends AbstractAction
{
    use ValidateSceneTrait;


    protected $auth;

    /**
     * @Middlewares({
     *     @Middleware(DashboardAuthMiddleware::class)
     * })
     * @RequestMapping(path="/client-new/detailjyfw", methods="get")
     */
    public function handle(): array
    {
        $params = $this->request->all();
        $user =user();
        if (empty($user)) {
            throw new CommonException(ErrorCode::AUTH_UNAUTHORIZED, '登入异常请重新登入');
        }

        $Client=ClientNew::query()->where('id',$params['clientId'])->first()->toArray();
        $res=Db::connection('b2b')->table('business_scope')->where('unique_id',$Client['uniqueId'])->pluck('TYPE')->toArray();
        $JyfwType=Db::connection('b2b')->table('business_scope_config')->pluck('name')->toArray();
        $data=[];
        foreach ($JyfwType as $v){
            if (in_array($v,$res)){
                $data[]=[
                  $v=>'开启'
                ];
            }else{
                $data[]=[
                    $v=>'关闭'
                ];
            }
        }
        return $data;
    }
}
